import jwt
from datetime import datetime, timedelta

KEY = "123456"


# 设置token
def set_token(name, id):
    payload = {"name": name, "id": id, "exp": datetime.now() + timedelta(hours=12)}
    return jwt.encode(payload=payload, key=KEY, algorithm="HS256")


# 获取token
def get_token(token):
    try:
        return jwt.decode(token, key=KEY, algorithms="HS256")
    except Exception as e:
        print(e)
        return None


print(get_token(
    "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiXHU1ZjIwXHU1MTc0IiwiaWQiOjEsImV4cCI6MTc0NzEwMDMyNH0.kXMBBeqKToF0Iim7Eyd-kOKbEkFDND2_9j-jE7fX2HI"))


# 判断空
def is_blank(name):
    if name is None or name.strip() == '':
        return True
    return False
